package com.hyh.music.controller;

import com.hyh.music.Result.Result;
import com.hyh.music.Result.Results;
import com.hyh.music.domain.domainDTO.ConsumerDTO;
import com.hyh.music.domain.domainDTO.ConsumerPageDTO;
import com.hyh.music.service.ConsumerService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author hyh
 * @version 1.0
 */
@Slf4j
@RestController
@RequestMapping("/admin/consumer")
public class ConsumerController {

    @Autowired
    ConsumerService consumerService;
    @GetMapping("page")
    public Result<Results> Page(ConsumerPageDTO consumerPageDTO) {
        log.info("consumer的分页查询{}", consumerPageDTO.getUsername());
        Results results = consumerService.Page(consumerPageDTO);
        return Result.success(results);
    }
    @PostMapping("/addConsumer")
    public Result addConsumer(@RequestBody ConsumerDTO consumerDTO){
        log.info("添加了用户{}",consumerDTO);
        consumerService.addConsumer(consumerDTO);
        return Result.success();
    }

    @DeleteMapping("/deleteUser")
    public Result deleteConsumerById(Integer id){
        log.info("删除了id为{}的用户",id);
        consumerService.delete(id);
        return Result.success();
    }

}
